package cn.com.xy.sms.sdk.ui.popu.part;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.Map;

import cn.com.xy.sms.sdk.Iservice.XyCallBack;
import cn.com.xy.sms.sdk.smsmessage.BusinessSmsMessage;
import cn.com.xy.sms.sdk.ui.R;
import cn.com.xy.sms.sdk.ui.popu.util.ChannelContentUtil;
import cn.com.xy.sms.sdk.ui.popu.util.ThemeUtil;
import cn.com.xy.sms.sdk.ui.popu.widget.SmartisanosTypeface;
import cn.com.xy.sms.sdk.util.StringUtils;

@SuppressLint("ResourceAsColor")
public class BubbleGeneralTwoTextBodyCMCC extends UIPart {

    private TextView mContentTextView = null;

    public BubbleGeneralTwoTextBodyCMCC(Activity context, BusinessSmsMessage message, XyCallBack callback, int layoutId,
                                        ViewGroup root, int partId) {
        super(context, message, callback, layoutId, root, partId);
    }

    @Override
    public void initUi() {
        mContentTextView = (TextView) mView.findViewById(R.id.duoqu_bubble_generalone_content);
    }

    @Override
    public void setContent(BusinessSmsMessage message, boolean isRebind) throws Exception {
        this.mMessage = message;
        if (message == null) {
            return;
        }
        String contStr = (String) mMessage.getMessageBody();
        if (StringUtils.isNull(contStr)) {
            mView.setVisibility(View.GONE);
            return;
        } else {
            mView.setVisibility(View.VISIBLE);
        }
        setViewStyle(mMessage);

        ChannelContentUtil.setText(mContentTextView, contStr, "");

        /* SMARTISAN-419 zhaoxiachao 20170217 start */
        if (SmartisanosTypeface.CLOCK != null) {
            mContentTextView.setTypeface(SmartisanosTypeface.CLOCK);
        }
        /* SMARTISAN-419 zhaoxiachao 20170217 end */

        /* SMARTISAN-501 zhaoxiachao 20170324 start */
        if(ChannelContentUtil.hasBottomBotton(message)){
            if(mContentTextView.getPaddingBottom() == 0){
                mContentTextView.setPadding(0, 0, 0, ChannelContentUtil.DUOQU_GENERAL_HAS_BOTTOM_PADDBOTTON);
            }
        }else {
            if(mContentTextView.getPaddingBottom() != 0){
                mContentTextView.setPadding(0, 0, 0, 0);
            }
        }
        /* SMARTISAN-501 zhaoxiachao 20170324 end */
    }

    /**
     * 设置View的样式
     *
     * @param message
     */
    private void setViewStyle(BusinessSmsMessage message) {
        // TODO Auto-generated method stub
        ThemeUtil.setViewBg(mContext, mView, "", R.drawable.duoqu_v_by_bg_1);
    }

    @Override
    public void changeData(Map<String, Object> param) {
        /* SMARTISAN-261 zhaoxiachao 20161129 start */
        if (param != null && !StringUtils.isNull(param.get(ChannelContentUtil.CHANGE_TRAIN) + "")) {
            return;
        }
        /* SMARTISAN-261 zhaoxiachao 20161129 end */
    }
}
